
// 防抖：N秒内只触发一次，如果N秒内再次触发则重新计算时间；
// 节流：N秒内只触发一次，如果N秒内再次触发也不会执行；
//节流
export const throttle = (fn,time)=>{
    let pre = 0
    return function (e){
        let now = Date.now()
        if(now-pre>time){
            pre = now
            fn.call(this,e)
        }
    }
}

//防抖
export const debounce = (fn,time)=>{
    let timer = null
    return function (e){
        if(timer){
            clearTimeout(timer)
        }
        timer = setTimeout(()=>{
            fn.call(this,e)
            timer = null
        },time)
    }
}